<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">




<title>委托与事件 - Autumoon - 博客园</title>
<meta name="keywords" content="白话C#系列,委托与事件">
<meta name="description" content="C#提供了委托机制来实现异步处理，也就是说，你向服务器发送请求以后就可以把精力用在做别的事情上，服务器返回请求后应用程序会自动调用你之前安排好的方法来处理接下来的工作。换句话说，你点好了菜，接下来就可以和朋友聊天，厨房做好了菜无论是叫号还是由服务员端到你桌上来，反正不用你再操心了。">



<link title="RSS" type="application/rss+xml" rel="alternate" href="http://www.cnblogs.com/Autumoon/rss">
<link title="RSD" type="application/rsd+xml" rel="EditURI" href="http://www.cnblogs.com/Autumoon/rsd.xml"> 
  



<link rel="stylesheet" type="text/css" href="index.css" media="all">
</head>
<body>
    <form name="Form1" method="post" action="http://www.cnblogs.com/Autumoon/archive/2008/07/05/1236346.html" id="Form1">
<div>
<input name="__VIEWSTATE" id="__VIEWSTATE" value="" type="hidden">
</div>

        
<!--done-->
<div id="home">
<div id="header">
	<div id="blogTitle">
		
<!--done-->
<h1><a id="Header1_HeaderTitle" class="headermaintitle" href="http://www.cnblogs.com/Autumoon/">Autumoon</a></h1>
<h2><a href="http://www.autumoon.com/" target="_top" title="欢迎访问Autumoon Lab！">www.Autumoon.com</a></h2>



		
	</div><!--end: blogTitle 博客的标题和副标题 -->
	<div id="navigator">
		
<!--done-->
			<ul id="navList">
				<li></li>
				<li></li>
				<li><a href="http://home.cnblogs.com/">主页</a></li>
				<li><a href="http://home.cnblogs.com/ing/">闪存</a></li>				
				<li></li>
				<li><a id="MyLinks1_ContactLink" accesskey="9" class="menu" href="http://space.cnblogs.com/msg/send/Autumoon">联系</a></li>
				<li><a id="MyLinks1_Admin" class="menu" href="http://www.cnblogs.com/Autumoon/admin/EditPosts.aspx">管理</a></li>
				<li><a id="MyLinks1_Syndication" class="menu" href="http://www.cnblogs.com/Autumoon/rss">订阅</a>
				<a id="MyLinks1_XMLLink" class="aHeaderXML" href="http://www.cnblogs.com/Autumoon/rss"><img src="rss.gif" alt="订阅" style="border-width: 0px;"></a></li>
			</ul>


		<div class="blogStats">
			
			
<!--done-->
随笔-71&nbsp;
文章-0&nbsp;
评论-326&nbsp;

			
		</div><!--end: blogStats -->
	</div><!--end: navigator 博客导航栏 -->
</div><!--end: header 头部 -->
<div id="main">
	<div id="mainContent">
	<div class="forFlow">
		
					
<!--done-->
<div id="topics">
	<div class="post">
		<h1 class="postTitle">
			<a id="ctl04_TitleUrl" class="postTitle2" href="http://www.cnblogs.com/Autumoon/archive/2008/07/05/1236346.html">委托与事件</a>
		</h1>
		<div class="clear"></div>
		<div class="postBody">
			<p><font size="2"><a href="http://www.cnblogs.com/Autumoon/archive/2008/04/16/1156864.html">【回目录】</a></font></p>
<p><font size="2">我们出去吃饭，总是喜欢去人多生意好的馆子，因为这样的馆子往往味道和服务都比较好（相信群众），而那些生意冷清的馆子往往无人问津。生意好的馆子固然有其长处，但去这样地方就餐又总是需要先排队等位置，所以排号是比较流行的方式。当然，如果这家馆子的座位充足，就不需要排号，但是上菜又比较慢。无论怎样，如果厨房一时半会儿无法做好你的菜，那么你就只好耐心地等待，在这个时候你可以做自己的事情，跟朋友聊天、玩手机或者看美女，没有人会傻傻地站在厨房门口目不转睛地盯着厨师手中的锅铲直到做好自己的菜。</font></p>
<p><font size="2">在软件开发工作中，我们也常常会遇到类似的问题，我们向某个服务器（或类似于服务器的东西）发送一个请求，需要获取到反馈信息后才能继续某项工作，但是如果这项工作不是最重要的或者目前唯一的工作项，我们完全没有必要让这个等待过程阻碍整个软件的使用，如果这样做了，那将获得非常糟糕的用户体验，就像我们看到有人一动不动地站在厨房门口等菜一样。</font></p>
<p><font size="2">C#提供了委托机制来实现异步处理，也就是说，你向服务器发送请求以后就可以把精力用在做别的事情上，服务器返回请求后应用程序会自动调用你之前安排好的方法来处理接下来的工作。换句话说，你点好了菜，接下来就可以和朋友聊天，厨房做好了菜无论是叫号还是由服务员端到你桌上来，反正不用你再操心了。</font></p>
<p><font size="2">下面我们先创建一个顾客类：</font></p>
<p><font size="2"></font></p>
<div style="margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; border-left-color: gray; width: 97.5%; cursor: text; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
<div style="padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 1:</span> <span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">class</span> Customer</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 2:</span> {</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 3:</span> <span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">int</span> ID { get; <span style="color: rgb(0, 0, 255);">private</span> set; }</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 4:</span>&nbsp; </pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 5:</span> <span style="color: rgb(0, 0, 255);">public</span> Customer(<span style="color: rgb(0, 0, 255);">int</span> id)</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 6:</span> {</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 7:</span> <span style="color: rgb(0, 0, 255);">this</span>.ID = id;</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 8:</span> }</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 9:</span> }</pre>
</div>
</div>
<p>&nbsp;</p>
<p><font size="2">在这个场景中，我们不需要赋予Customer类太多属性，我们假设这家餐馆采用的方式是叫号而不是由服务员把菜端到每个顾客桌上，所以Customer类只要有个ID号就够了。</font></p>
<p><font size="2">接下来我们来实现这个叫号的方法，虽然很简单，但是肯定不是只有一家餐馆采用这种方式，因此我们把这个方法放在单独的一个类里面：</font></p>
<div style="margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; border-left-color: gray; width: 97.5%; cursor: text; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
<div style="padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 1:</span> <span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">class</span> DelegateDemo</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 2:</span> {</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 3:</span> <span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">static</span> <span style="color: rgb(0, 0, 255);">void</span> CallCustomer(Customer customer)</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 4:</span> {</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 5:</span> <span style="color: rgb(0, 0, 255);">if</span> (customer != <span style="color: rgb(0, 0, 255);">null</span>)</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 6:</span> {</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 7:</span> Console.WriteLine(<span style="color: rgb(0, 96, 128);">"Customer ID: "</span> + customer.ID);</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 8:</span> }</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 9:</span> }</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 10:</span> }</pre>
</div>
</div>
<p><font size="2">然后我们来创建最重要的类，餐厅类：</font></p>
<div style="margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; border-left-color: gray; width: 97.5%; cursor: text; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
<div style="padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 1:</span> <span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">class</span> SampleRestaurant</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 2:</span> {</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 3:</span> <span style="color: rgb(0, 0, 255);">public</span> List&lt;Customer&gt; Customers { get; <span style="color: rgb(0, 0, 255);">private</span> set; }</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 4:</span>&nbsp; </pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 5:</span> <span style="color: rgb(0, 0, 255);">public</span> SampleRestaurant()</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 6:</span> {</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 7:</span> <span style="color: rgb(0, 0, 255);">this</span>.Customers = <span style="color: rgb(0, 0, 255);">new</span> List&lt;Customer&gt;();</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 8:</span>&nbsp; </pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 9:</span> <span style="color: rgb(0, 0, 255);">for</span> (<span style="color: rgb(0, 0, 255);">int</span> index = 1; index &lt;= 10; index++)</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 10:</span> {</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 11:</span> Customers.Add(<span style="color: rgb(0, 0, 255);">new</span> Customer(index));</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 12:</span> }</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 13:</span> }</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 14:</span>&nbsp; </pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 15:</span> <span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">delegate</span> <span style="color: rgb(0, 0, 255);">void</span> EnumCustomerCallback(Customer customer);</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 16:</span>&nbsp; </pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 17:</span> <span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">void</span> EnumCustomers(EnumCustomerCallback callback)</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 18:</span> {</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 19:</span> <span style="color: rgb(0, 0, 255);">foreach</span> (var customer <span style="color: rgb(0, 0, 255);">in</span> Customers)</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 20:</span> {</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 21:</span> callback(customer);</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 22:</span> }</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 23:</span> }</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 24:</span> }</pre>
</div>
</div>
<p><font size="2">在这个餐厅类里面，有一个顾客的集合，表示当前餐厅里所有的顾客，我们先往这个集合里面塞10个顾客进去以备待会儿叫号。然后我们在这个类里面声明了一个委托EnumCustomerCallback，并限定了它的函数签名。要使用这个委托的函数就必须符合该委托的签名形式。例如，该餐馆采用叫号的方式，也就是说我们要把DelegateDemo.CallCustomers方法传递给EnumCustomerCallback委托，因此它俩的函数签名是一致的。然后我们还定义了一个EnumCustomers方法，该方法的以EnumCustomerCallback委托为参数。该方法执行的内容是挨个遍历当前所有顾客，至于遍历到每个顾客是采取什么样的方式，叫号还是有服务员端菜呢，取决于传递给当前委托的方法来执行。</font></p>
<p><font size="2">好，接下来我们来执行这段代码看看效果：</font></p>
<div style="margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; border-left-color: gray; width: 97.5%; cursor: text; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
<div style="padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 1:</span> <span style="color: rgb(0, 0, 255);">static</span> <span style="color: rgb(0, 0, 255);">void</span> Main(<span style="color: rgb(0, 0, 255);">string</span>[] args)</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 2:</span> {</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 3:</span> SampleRestaurant restaurant = <span style="color: rgb(0, 0, 255);">new</span> SampleRestaurant();</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 4:</span> SampleRestaurant.EnumCustomerCallback callCustomer = <span style="color: rgb(0, 0, 255);">new</span> SampleRestaurant.EnumCustomerCallback(DelegateDemo.CallCustomer);</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 5:</span> restaurant.EnumCustomers(callCustomer);</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 6:</span>&nbsp; </pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 7:</span> Console.ReadLine();</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 8:</span> }</pre>
</div>
</div>
<p><font size="2">在这段代码的第4行，我们创建了一个委托实例callCustomers，并把叫号的方法DelegateDemo.CallCustomers传递给它座位该餐馆上菜的方式。然后我们再把这个方式传递给该餐厅的遍历顾客的方法，让它在遍历到每个顾客的时候采用老板设定好了的方式去执行。</font></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><font size="2">下面的截图就是以上代码执行的结果，喇叭里挨个叫出顾客的编号，通知他们去取餐：</font></p>
<p><font size="2"><img title="Delegate Demo Result" style="border-width: 0px;" alt="Delegate Demo Result" src="delegatedemoresult_1.jpg" border="0" height="365" width="529"> </font></p>
<p><font size="2">接下来我们来介绍一下事件机制，之所以把事件放在委托后面讲，是因为事件是在委托的基础上实现的。这一次我们站在厨师的角度来看待什么是事件。</font></p>
<p><font size="2">作为一个厨师，炒菜是最基本的工作内容，而对于餐厅的服务员来说，可以拿着点菜单去叫厨师来炒菜，因此这就存在一个观察者模式，即发布和订阅的机制。服务员发布说：“顾客要个青椒肉丝”，厨师订阅说：“行，我马上炒个青椒肉丝”。定义事件需要注意的是，事件需要两个参数，一是引发该事件的对象，本例中是负责点菜的服务员；二是事件消息对象。其中，事件消息对象必须派生自System.EventArgs类。</font></p>
<p><font size="2">因此我们先来设计一个点菜单作为事件消息类：</font></p>
<div style="margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; border-left-color: gray; width: 97.5%; cursor: text; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
<div style="padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 1:</span> <span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">class</span> OrderEventArgs : EventArgs</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 2:</span> {</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 3:</span> <span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">string</span> DishName { get; set; }</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 4:</span> <span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">int</span> Amount { get; set; }</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 5:</span> }</pre>
</div>
</div>
<p><font size="2">在这个点菜单中，我们只包含了菜名和数量，因为对于厨师来说，他只要知道这两个基本信息就够了。接下来我们来定义这个厨师类：</font></p>
<div style="margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; border-left-color: gray; width: 97.5%; cursor: text; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
<div style="padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 1:</span> <span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">class</span> Cook</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 2:</span> {</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 3:</span> <span style="color: rgb(0, 0, 255);">public</span> Waitress TheWaitress { get; <span style="color: rgb(0, 0, 255);">private</span> set; }</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 4:</span>&nbsp; </pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 5:</span> <span style="color: rgb(0, 0, 255);">public</span> Cook(Waitress waitress)</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 6:</span> {</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 7:</span> <span style="color: rgb(0, 0, 255);">this</span>.TheWaitress = waitress;</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 8:</span> <span style="color: rgb(0, 0, 255);">this</span>.TheWaitress.OnOrderHandler += <span style="color: rgb(0, 0, 255);">new</span> Waitress.OrderEventHandler(waitress_OnOrderHandler);</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 9:</span> }</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 10:</span>&nbsp; </pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 11:</span> <span style="color: rgb(0, 0, 255);">void</span> waitress_OnOrderHandler(<span style="color: rgb(0, 0, 255);">object</span> sender, OrderEventArgs e)</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 12:</span> {</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 13:</span> Console.WriteLine(<span style="color: rgb(0, 96, 128);">"I cook "</span> + e.Amount + <span style="color: rgb(0, 96, 128);">" "</span> + e.DishName + <span style="color: rgb(0, 96, 128);">"."</span>);</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 14:</span> }</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 15:</span> }</pre>
</div>
</div>
<p><font size="2">在厨师类中包含了一个Waitress对象，这表示发布者，也就是叫厨师炒菜的服务员。第8行，厨师把自己添加进预订者列表，也就是说在服务员下单子的时候，厨房里得有现成的厨师才行，如果厨房里没有厨师，服务员发布了点菜事件也没人接招。</font></p>
<p><font size="2">然后我们来看看事件的发布者，服务员：</font></p>
<div style="margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; border-left-color: gray; width: 97.5%; cursor: text; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
<div style="padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 1:</span> <span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">class</span> Waitress</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 2:</span> {</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 3:</span> <span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">delegate</span> <span style="color: rgb(0, 0, 255);">void</span> OrderEventHandler(<span style="color: rgb(0, 0, 255);">object</span> sender, OrderEventArgs e);</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 4:</span> <span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">event</span> OrderEventHandler OnOrderHandler;</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 5:</span>&nbsp; </pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 6:</span> <span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">void</span> Order(<span style="color: rgb(0, 0, 255);">string</span> dishName, <span style="color: rgb(0, 0, 255);">int</span> amount)</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 7:</span> {</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 8:</span> <span style="color: rgb(0, 0, 255);">if</span> (String.IsNullOrEmpty(dishName) || amount &lt;= 0)</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 9:</span> {</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 10:</span> <span style="color: rgb(0, 0, 255);">return</span>;</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 11:</span> }</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 12:</span>&nbsp; </pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 13:</span> OrderEventArgs orderEventArgs = <span style="color: rgb(0, 0, 255);">new</span> OrderEventArgs { DishName = dishName, Amount = amount };</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 14:</span>&nbsp; </pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 15:</span> <span style="color: rgb(0, 0, 255);">if</span> (OnOrderHandler != <span style="color: rgb(0, 0, 255);">null</span>)</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 16:</span> {</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 17:</span> OnOrderHandler(<span style="color: rgb(0, 0, 255);">this</span>, orderEventArgs);</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 18:</span> }</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 19:</span> }</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 20:</span> }</pre>
</div>
</div>
<p><font size="2">在这个服务员类里面，我们首先定义了一个带有两个参数的委托以及一个事件。委托的两个参数一个是发布者对象，另一个是事件信息对象。然后，服务员类还提供了一个点餐方法，点餐方法创建一个事件信息类（点菜单），如果事件的订阅者不为空，也就是说厨房里目前有厨师，那么服务员就会把这个点菜单发送过去，而事件的订阅者会有专门的方法来处理这个事件。</font></p>
<div style="margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; border-left-color: gray; width: 97.5%; cursor: text; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
<div style="padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 1:</span> <span style="color: rgb(0, 0, 255);">static</span> <span style="color: rgb(0, 0, 255);">void</span> Main(<span style="color: rgb(0, 0, 255);">string</span>[] args)</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 2:</span> {</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 3:</span> Waitress waitress = <span style="color: rgb(0, 0, 255);">new</span> Waitress();</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 4:</span> Cook cook = <span style="color: rgb(0, 0, 255);">new</span> Cook(waitress);</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 5:</span>&nbsp; </pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 6:</span> waitress.Order(<span style="color: rgb(0, 96, 128);">"QingJiaoRouSi"</span>, 1);</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 7:</span>&nbsp; </pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 8:</span> Console.ReadLine();</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 9:</span> }</pre>
</div>
</div>
<p><font size="2"><img title="Restaurant" style="border-width: 0px;" alt="Restaurant" src="restaurant_3.jpg" border="0" height="387" width="570">&nbsp;</font></p>
<div id="digg_block">
<div id="div_digg">										
	<div class="diggit" onclick="DiggIt(1236346,28598,1)"> 
		<span class="diggnum" id="digg_count_1236346">0</span>
	</div>
	<div class="buryit" onclick="DiggIt(1236346,28598,2)"> 
		<span class="burynum" id="bury_count_1236346">0</span>
	</div>
	<div class="clear"></div>
	<span style="display: none;" id="span_isdigged_1236346">0</span>	
	<div class="diggword" id="digg_word_1236346">(请您对文章做出评价)</div>	
</div>
</div>
<div class="clear"></div>
<div id="post_next_prev">
<a href="http://www.cnblogs.com/Autumoon/archive/2008/07/01/1233476.html">« </a> 上一篇：<a href="http://www.cnblogs.com/Autumoon/archive/2008/07/01/1233476.html" title="发布于2008-07-01 17:42">Touch Diamond Remote —— 世界就在指尖</a><br>
<a href="http://www.cnblogs.com/Autumoon/archive/2008/07/08/1238456.html">» </a> 下一篇：<a href="http://www.cnblogs.com/Autumoon/archive/2008/07/08/1238456.html" title="发布于2008-07-08 21:06">Touch Diamond DIY —— 自己动手 丰衣足食</a><br>
</div>








		</div>
		<div class="postDesc">posted @ 2008-07-05 18:48 <a href="http://www.cnblogs.com/Autumoon/">Autumoon</a> 阅读(925) <a href="#commentform">评论(7)</a> &nbsp;<a href="http://www.cnblogs.com/Autumoon/admin/EditPosts.aspx?postid=1236346">编辑</a> <a href="http://www.cnblogs.com/Autumoon/AddToFavorite.aspx?id=1236346">收藏</a> <a href="#" onclick="PutInWz();return false;">网摘</a>  所属分类: <a href="http://www.cnblogs.com/Autumoon/category/131874.html">白话C#系列</a></div>
	</div>
	<img src="1236346.html" height="1" width="1">
	
<!--
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
<rdf:Description
rdf:about="http://www.cnblogs.com/Autumoon/archive/2008/07/05/1236346.html"
dc:identifier="http://www.cnblogs.com/Autumoon/archive/2008/07/05/1236346.html"
dc:title=""
trackback:ping="http://www.cnblogs.com/Autumoon/services/trackbacks/1236346.aspx" />
</rdf:RDF>
-->

</div><!--end: topics 文章、评论容器-->
<a name="pagedcomment"></a>
<!--done-->
<br>
<div class="feedback_area_title">发表评论</div>
<div class="feedbackNoItems"><span id="span_comment_maxid" style="display: none;">1329638</span></div>
	

		<div class="feedbackItem">
			<div class="feedbackListSubtitle">
				<div class="feedbackManage">
					&nbsp;&nbsp;<a onclick='ReplyComment("Marklee",1251744,"EYBnOZk5LnDkrZB04ECNTNOjVwOo2chiZIdfeFrot04Q1SCVM+ny/A==")' href="http://www.cnblogs.com/Autumoon/archive/2008/07/05/1236346.html#commentform">回复</a>&nbsp;&nbsp;<a onclick='QuoteComment(1251744,"EYBnOZk5LnDkrZB04ECNTNOjVwOo2chiZIdfeFrot04Q1SCVM+ny/A==")' href="http://www.cnblogs.com/Autumoon/archive/2008/07/05/1236346.html#commentform">引用</a>&nbsp;&nbsp;<a title="查看该作者发表过的评论" href="http://www.cnblogs.com/CommentsByAuthor.aspx?author=Marklee" target="_top">查看</a>&nbsp;&nbsp;&nbsp;&nbsp;
				</div>
				<a href="#1251744">#1楼</a><a name="1251744" id="comment_anchor_1251744"></a>2008-07-11 16:09 | <a id="Comments1_CommentList_ctl00_NameLink" href="http://www.cnblogs.com/marklch/" target="_top">Marklee</a>&nbsp;<a href="http://space.cnblogs.com/msg/send/Marklee" title="给此人发送站内短消息" class="sendMsg2This">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a>
			</div>
			<div class="feedbackCon">
				<span id="comment_body_1251744" class="blog_comment_body">那个委托的例子，把委托作为参数传如方法里去，用的是匿名函数的方法把
<br>这个例子很有味道，仔细研究</span><br>
			</div>
		</div>
	
		<div class="feedbackItem">
			<div class="feedbackListSubtitle">
				<div class="feedbackManage">
					&nbsp;&nbsp;<a onclick='ReplyComment("陈晨",1258307,"TMAoIwCAJPHGEKB3It88EImsinkw1T3pXLhkbKBavjo6Nuzy/DSdLQ==")' href="http://www.cnblogs.com/Autumoon/archive/2008/07/05/1236346.html#commentform">回复</a>&nbsp;&nbsp;<a onclick='QuoteComment(1258307,"TMAoIwCAJPHGEKB3It88EImsinkw1T3pXLhkbKBavjo6Nuzy/DSdLQ==")' href="http://www.cnblogs.com/Autumoon/archive/2008/07/05/1236346.html#commentform">引用</a>&nbsp;&nbsp;<a title="查看该作者发表过的评论" href="http://www.cnblogs.com/CommentsByAuthor.aspx?author=%e9%99%88%e6%99%a8" target="_top">查看</a>&nbsp;&nbsp;&nbsp;&nbsp;
				</div>
				<a href="#1258307">#2楼</a><a name="1258307" id="comment_anchor_1258307"></a>2008-07-16 21:45 | <a id="Comments1_CommentList_ctl01_NameLink" href="http://www.cnblogs.com/freshman0216/" target="_top">陈晨</a>&nbsp;<a href="http://space.cnblogs.com/msg/send/%e9%99%88%e6%99%a8" title="给此人发送站内短消息" class="sendMsg2This">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a>
			</div>
			<div class="feedbackCon">
				<span id="comment_body_1258307" class="blog_comment_body">仔细研究了这个例子
<br>终于对事件有点感觉了，谢谢</span><br>
			</div>
		</div>
	
		<div class="feedbackItem">
			<div class="feedbackListSubtitle">
				<div class="feedbackManage">
					&nbsp;&nbsp;<a onclick='ReplyComment("礼拜一",1292615,"k/q536nguwD7czKvtAO9o5rxatNJlkovqO31sHJ0m55DpzMDslOAJg==")' href="http://www.cnblogs.com/Autumoon/archive/2008/07/05/1236346.html#commentform">回复</a>&nbsp;&nbsp;<a onclick='QuoteComment(1292615,"k/q536nguwD7czKvtAO9o5rxatNJlkovqO31sHJ0m55DpzMDslOAJg==")' href="http://www.cnblogs.com/Autumoon/archive/2008/07/05/1236346.html#commentform">引用</a>&nbsp;&nbsp;<a title="查看该作者发表过的评论" href="http://www.cnblogs.com/CommentsByAuthor.aspx?author=%e7%a4%bc%e6%8b%9c%e4%b8%80" target="_top">查看</a>&nbsp;&nbsp;&nbsp;&nbsp;
				</div>
				<a href="#1292615">#3楼</a><a name="1292615" id="comment_anchor_1292615"></a>2008-08-20 17:02 | <a id="Comments1_CommentList_ctl02_NameLink" href="http://www.cnblogs.com/zyh-nhy/" target="_top">礼拜一</a>&nbsp;<a href="http://space.cnblogs.com/msg/send/%e7%a4%bc%e6%8b%9c%e4%b8%80" title="给此人发送站内短消息" class="sendMsg2This">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a>
			</div>
			<div class="feedbackCon">
				<span id="comment_body_1292615" class="blog_comment_body">半仙儿，问一下~
<br>public Waitress TheWaitress;
<br>public Cook(Waitress waitress)
<br>{
<br>     this.TheWaitress = waitress;
<br>     this.TheWaitress.OnOrderHandler += new Waitress.OrderEventHandler(waitress_OnOrderHandler);
<br>}
<br>这个为啥放在Cook类里？
<br>为啥不在Cook类里只放展现的内容，而把事件绑定放到Main里？
<br>这样的话Cook是不是更干净一些？</span><br>
			</div>
		</div>
	
		<div class="feedbackItem">
			<div class="feedbackListSubtitle">
				<div class="feedbackManage">
					&nbsp;&nbsp;<a onclick='ReplyComment("无名100",1302096,"")' href="http://www.cnblogs.com/Autumoon/archive/2008/07/05/1236346.html#commentform">回复</a>&nbsp;&nbsp;<a onclick='QuoteComment(1302096,"")' href="http://www.cnblogs.com/Autumoon/archive/2008/07/05/1236346.html#commentform">引用</a>&nbsp;&nbsp;&nbsp;&nbsp;
				</div>
				<a href="#1302096">#4楼</a><a name="1302096" id="comment_anchor_1302096"></a> 61.178.74.* 2008-08-29 16:11 | <a id="Comments1_CommentList_ctl03_NameLink" target="_blank">无名100[未注册用户]</a>
			</div>
			<div class="feedbackCon">
				<span id="comment_body_1302096" class="blog_comment_body">也可以参考一下下面的文章:
<br>
<br><a href="http://www.tracefact.net/CSharp-Programming/Delegates-and-Events-in-CSharp.aspx" target="_new" rel="nofollow">http://www.tracefact.net/CSharp-Programming/Delegates-and-Events-in-CSharp.aspx</a></span><br>
			</div>
		</div>
	
		<div class="feedbackItem">
			<div class="feedbackListSubtitle">
				<div class="feedbackManage">
					&nbsp;&nbsp;<a onclick='ReplyComment("无名100",1302102,"")' href="http://www.cnblogs.com/Autumoon/archive/2008/07/05/1236346.html#commentform">回复</a>&nbsp;&nbsp;<a onclick='QuoteComment(1302102,"")' href="http://www.cnblogs.com/Autumoon/archive/2008/07/05/1236346.html#commentform">引用</a>&nbsp;&nbsp;&nbsp;&nbsp;
				</div>
				<a href="#1302102">#5楼</a><a name="1302102" id="comment_anchor_1302102"></a> 61.178.74.* 2008-08-29 16:13 | <a id="Comments1_CommentList_ctl04_NameLink" target="_blank">无名100[未注册用户]</a>
			</div>
			<div class="feedbackCon">
				<span id="comment_body_1302102" class="blog_comment_body">我发的留言怎么不见了,不知道是不是被删了.做学问要大度一点.</span><br>
			</div>
		</div>
	
		<div class="feedbackItem">
			<div class="feedbackListSubtitle">
				<div class="feedbackManage">
					&nbsp;&nbsp;<a onclick='ReplyComment("Autumoon",1302700,"M6sed0jREdUJvqEIDK6Tcwj6B9iFJq2qtJqYsoSPdqAKnXcYRqIo3A==")' href="http://www.cnblogs.com/Autumoon/archive/2008/07/05/1236346.html#commentform">回复</a>&nbsp;&nbsp;<a onclick='QuoteComment(1302700,"M6sed0jREdUJvqEIDK6Tcwj6B9iFJq2qtJqYsoSPdqAKnXcYRqIo3A==")' href="http://www.cnblogs.com/Autumoon/archive/2008/07/05/1236346.html#commentform">引用</a>&nbsp;&nbsp;<a title="查看该作者发表过的评论" href="http://www.cnblogs.com/CommentsByAuthor.aspx?author=Autumoon" target="_top">查看</a>&nbsp;&nbsp;&nbsp;&nbsp;
				</div>
				<a href="#1302700">#6楼</a><a name="1302700" id="comment_anchor_1302700"></a>[<span class="louzhu">楼主</span>]2008-08-30 08:50 | <a id="Comments1_CommentList_ctl05_NameLink" href="http://www.cnblogs.com/Autumoon/" target="_top">Autumoon</a>&nbsp;<a href="http://space.cnblogs.com/msg/send/Autumoon" title="给此人发送站内短消息" class="sendMsg2This">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a>
			</div>
			<div class="feedbackCon">
				<span id="comment_body_1302700" class="blog_comment_body">@无名100
<br>我不排斥别人写的东西，但请就事论事，写委托与事件的文章多了去了，你是不是打算在我这里列个目录呢？</span><br>
			</div>
		</div>
	
		<div class="feedbackItem">
			<div class="feedbackListSubtitle">
				<div class="feedbackManage">
					&nbsp;&nbsp;<a onclick='ReplyComment("追忆似水流年",1329638,"AJzKbDes6wN29VQDIHdUUDhAvWjwrPCbHUI2E7xHsUexGZ1gIkD2ng==")' href="http://www.cnblogs.com/Autumoon/archive/2008/07/05/1236346.html#commentform">回复</a>&nbsp;&nbsp;<a onclick='QuoteComment(1329638,"AJzKbDes6wN29VQDIHdUUDhAvWjwrPCbHUI2E7xHsUexGZ1gIkD2ng==")' href="http://www.cnblogs.com/Autumoon/archive/2008/07/05/1236346.html#commentform">引用</a>&nbsp;&nbsp;<a title="查看该作者发表过的评论" href="http://www.cnblogs.com/CommentsByAuthor.aspx?author=%e8%bf%bd%e5%bf%86%e4%bc%bc%e6%b0%b4%e6%b5%81%e5%b9%b4" target="_top">查看</a>&nbsp;&nbsp;&nbsp;&nbsp;
				</div>
				<a href="#1329638">#7楼</a><a name="1329638" id="comment_anchor_1329638"></a><a name="Post"></a>2008-09-29 14:57 | <a id="Comments1_CommentList_ctl06_NameLink" href="http://www.cnblogs.com/purplefox2008/" target="_top">追忆似水流年</a>&nbsp;<a href="http://space.cnblogs.com/msg/send/%e8%bf%bd%e5%bf%86%e4%bc%bc%e6%b0%b4%e6%b5%81%e5%b9%b4" title="给此人发送站内短消息" class="sendMsg2This">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a>
			</div>
			<div class="feedbackCon">
				<span id="comment_body_1329638" class="blog_comment_body">楼主的几个类中的属性set和get访问器写的好像不对,比如类Customer中public int ID { get; private set; }.</span><br>
			</div>
		</div>
	

<div id="comment_form" class="commentform">



<div id="divCommentShow"></div>
<div id="comment_nav" style="text-align: right;"><span id="span_refresh_tips"></span><a href="###" onclick="return RefreshCommentList(1236346);" name="commentform" id="lnk_RefreshComments">刷新评论列表</a>&nbsp; <a href="###" onclick="return RefreshPage();">刷新页面</a>&nbsp; <a href="#top">返回页首</a></div>
<div id="commentform_title">发表评论 <span class="ad_commentbox_up"><a href="http://www.cnblogs.com/" target="_top">博客园首页</a>&nbsp; <a href="http://news.cnblogs.com/" target="_top">IT新闻</a>&nbsp; <a href="http://home.cnblogs.com/ing/" target="_top">闪存</a>&nbsp; <a href="http://job.cnblogs.com/" target="_top">招聘</a>&nbsp; <a href="http://a4.yeshj.com/rd/34143/" target="_top">学英语</a></span></div>
<span id="tip_comment" style="color: Red;"></span>
<p>
昵称：<input name="ctl05$tbCommentAuthor" id="ctl05_tbCommentAuthor" class="author" value="解然" disabled="disabled" type="text">
</p>
<p>
主页：<input name="ctl05$tbCommentAuthorUrl" id="ctl05_tbCommentAuthorUrl" class="url" value="http://www.cnblogs.com/xieran/" disabled="disabled" type="text">
</p>
<p>
</p><div class="commentbox_title">
<div class="commentbox_title_left">评论内容：</div>
<div class="commentbox_title_right">
<img id="ubb_quote" class="comment_icon" src="quote.gif" alt="引用" title="添加引用" onclick="insertUBB('tbCommentBody','quote')">
<img id="ubb_bold" class="comment_icon" src="b.png" alt="粗体" title="添加粗体" onclick="insertUBB('tbCommentBody','b')">
<img id="ubb_url" class="comment_icon" src="lk.png" alt="链接" title="添加链接" onclick="insertUbbUrl('tbCommentBody')">
<img id="ubb_indent" class="comment_icon" src="indent.png" alt="缩进" title="添加首行缩进" onclick="insertIndent('tbCommentBody')">
<img id="ubb_img" class="comment_icon" src="img.gif" alt="图片" title="添加图片" onclick="insertUbbImg('tbCommentBody')">
<img id="ubb_code" class="comment_icon" style="" src="insertcode.gif" alt="代码" title="添加代码" onclick="insertUbbCode()">
</div>
</div>
<div class="clear"></div>
<textarea id="tbCommentBody" class="comment_textarea" onkeydown="return clt_enter(event)"></textarea>

<p>
<input id="btn_comment_submit" class="comment_btn" value="提交" onclick="PostComment();return false;" type="button">
&nbsp;&nbsp;<span id="span_comment_canceledit" style="display: none;"><a href="###" onclick="return CancelCommentEdit()">不改了</a>&nbsp;&nbsp;</span><a href="http://passport.cnblogs.com/logout.aspx?ReturnUrl=http%3a%2f%2fwww.cnblogs.com%2fAutumoon%2farchive%2f2008%2f07%2f05%2f1236346.html%3flogout%3d1%23commentform" onclick="return confirm('确认注销吗？')">注销</a>&nbsp;&nbsp;<a id="ctl05_lnkSubscribe" title="邮件订阅回复通知" onclick="return SubscribeComment();" href="http://www.cnblogs.com/UI/Controls/#%23%23">订阅回复</a>
</p>
<p>
[使用Ctrl+Enter键快速提交]
</p>
<div style="display: none;">
<span id="comment_edit_id"></span><span id="span_parentcomment_id">0</span>
<span id="span_parent_id">1236346</span>
<span id="span_comment_replyto"></span>
<span id="span_comment_title">委托与事件</span>
<span id="span_comment_posted"></span>
</div>

<div class="itnews c_ad_block" id="itnews">
<a href="http://news.cnblogs.com/" target="_top">IT新闻</a>:<br>

          ·  <a href="http://news.cnblogs.com/n/55140/" target="_top">《星际争霸2》"刀锋女王"重金属主题音乐视频</a><br>
	
          ·  <a href="http://news.cnblogs.com/n/55139/" target="_top">中国站长最郁闷的几件事情</a><br>
	
          ·  <a href="http://news.cnblogs.com/n/55138/" target="_top">苹果Vs谷歌：手机领域谁怕谁？</a><br>
	
          ·  <a href="http://news.cnblogs.com/n/55137/" target="_top">摩托罗拉：豪赌Android的希望与隐忧</a><br>
	
          ·  <a href="http://news.cnblogs.com/n/55136/" target="_top">分众新坐标：楼宇是过去 未来在手机和互联网</a><br>
	
</div>


<div id="ad_under_comment" class="c_ad_block">
<a href="http://a4.yeshj.com/rd/34138/" target="_top">每天10分钟，轻松学英语</a><br><br>
<div id="google_ads_div_cnblogs_blogpost_bottom1">
<iframe src="index_1.html" style="border: 0pt none ;" marginheight="0" marginwidth="0" name="google_ads_iframe_cnblogs_blogpost_bottom1" id="google_ads_iframe_cnblogs_blogpost_bottom1" scrolling="no" frameborder="0" height="60" width="468"></iframe></div>

<br>
<div id="google_ads_div_cnblogs_blogpost_bottom">
<iframe src="index_2.html" style="border: 0pt none ;" marginheight="0" marginwidth="0" name="google_ads_iframe_cnblogs_blogpost_bottom" id="google_ads_iframe_cnblogs_blogpost_bottom" scrolling="no" frameborder="0" height="250" width="300"></iframe></div>

</div>
<div id="site_nav_under" class="c_ad_block">
网站导航：<br>
<a href="http://www.cnblogs.com/" target="_top">博客园首页</a> &nbsp;<a href="http://news.cnblogs.com/" target="_top">IT新闻</a> &nbsp;<a href="http://home.cnblogs.com/" target="_top">个人主页</a> &nbsp;<a href="http://home.cnblogs.com/ing/" target="_top">闪存</a> &nbsp;<a href="http://job.cnblogs.com/" target="_top">程序员招聘</a> &nbsp;<a href="http://space.cnblogs.com/" target="_top">社区</a> &nbsp;<a href="http://space.cnblogs.com/q/" target="_top">博问</a> &nbsp;<a href="http://wz.cnblogs.com/" target="_top">网摘</a>
</div>
<div id="ad_under_comment2" class="c_ad_block">
<a href="http://www.china-pub.com/STATIC07/0912/zh_ndcx_091212.asp" target="_top"><img src="chinapub_20091222.jpg" alt="" style="border: 0px none ;"></a><br>
<a href="http://www.china-pub.com/itbook/" target="_top">China-pub 计算机图书网上专卖店！6.5万品种2-8折！</a><br>
<a href="http://www.china-pub.com/static07/0901/zh_jueba_090121.asp" target="_top">China-Pub 计算机绝版图书按需印刷服务</a><br>
</div>


<div id="div_commentbox_nav" class="c_ad_block">
链接：<a href="http://www.cnblogs.com/Autumoon/archive/2008/07/05/1236346.html?switchskin=1#skinlist">切换模板</a><br>
</div>
<div id="relative_search"><br><b>相关搜索:</b><br> <a href="http://zzk.cnblogs.com/s?w=%e7%99%bd%e8%af%9dC%23%e7%b3%bb%e5%88%97" target="_top">白话C#系列</a> </div><div id="relative_search"><br><b>在知识库中查看：</b><br> <a href="http://kb.cnblogs.com/a/1236346/">委托与事件</a></div>

</div>




				
	</div><!--end: forFlow -->
	</div><!--end: mainContent 主体内容容器-->

	<div id="sideBar">
		<div id="sideBarMain">
			
<!--done-->
<div class="newsItem">
<h3 class="catListTitle">公告</h3>
	<p align="center"><embed src="world001-blue.swf" type="application/x-shockwave-flash" wmode="transparent" height="92" width="175"><br>
<br>
Since&nbsp;May 31, 1998.<br><!--<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#88;&#105;&#110;&#119;&#101;&#110;&#67;&#104;&#101;&#110;&#103;&#64;&#103;&#109;&#97;&#105;&#108;&#46;&#99;&#111;&#109;"><img height=21 alt="" src="http://images.cnblogs.com/cnblogs_com/zerocool/MyGmailLink.png" width=175 border=0 /></a><br/><br/>--><img src="r_mvp.png" alt="MVP (Visual C#)"><br><br></p><div style=""><table style="" cellpadding="4" cellspacing="0"><tbody><tr align="center"><td style=""><a href="http://www.douban.com/subject/1477390/" title="代码大全（第2版）" target="_top"><img src="s1495029.jpg" border="0"></a></td><td style=""><a href="http://www.douban.com/subject/3883231/" title="Pro Silverlight 3 in C#" target="_top"><img src="s3900991.jpg" border="0"></a></td></tr><tr align="center"><td style=""><a href="http://www.douban.com/subject/3696561/" title="世界又热又平又挤" target="_top"><img src="s3763074.jpg" border="0"></a></td><td style=""><a href="http://www.douban.com/subject/1085660/" title="尽管去做

Getting Things Done The Art of Stress-free Productivity" target="_top"><img src="s1796471.jpg" border="0"></a></td></tr><tr align="center"><td style=""><a href="http://www.douban.com/subject/1136852/" title="南怀瑾选集（第三卷）" target="_top"><img src="s2177899.jpg" border="0"></a></td></tr><tr><td colspan="2" align="center"><a href="http://www.douban.com/people/XinwenCheng/" target="_top">我的豆瓣主页</a></td></tr></tbody></table></div><br><div id="profile_block"><a href="http://home.cnblogs.com/Autumoon/" target="_top">我的主页</a>&nbsp; <a href="http://home.cnblogs.com/Autumoon/detail/" target="_top">个人资料</a><br><a href="http://home.cnblogs.com/Autumoon/ing/" target="_top">我的闪存</a>&nbsp; <a href="http://space.cnblogs.com/msg/send/Autumoon" target="_top">发短消息</a></div>
</div>

			<div id="calendar"></div>
			
			<div id="leftcontentcontainer">
				
<div class="catListPostCategory">
<h3 class="catListTitle">随笔分类<span style="font-size: 11px; font-weight: normal;">(69)</span></h3>

<ul>

<li><a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl01_Link" href="http://www.cnblogs.com/Autumoon/category/151002.html">.NET程序员技术面试迷你手册（C#版）(5)</a> <a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl01_RssLink" title="Subscribe to .NET程序员技术面试迷你手册（C#版）(5)" href="http://www.cnblogs.com/Autumoon/category/151002.html/rss">(rss)</a></li>

<li><a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl02_Link" href="http://www.cnblogs.com/Autumoon/category/102693.html">Autumoon Code Library(1)</a> <a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl02_RssLink" title="Subscribe to Autumoon Code Library(1)" href="http://www.cnblogs.com/Autumoon/category/102693.html/rss">(rss)</a></li>

<li><a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl03_Link" href="http://www.cnblogs.com/Autumoon/category/112473.html">C# 3.0 探索之旅(9)</a> <a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl03_RssLink" title="Subscribe to C# 3.0 探索之旅(9)" href="http://www.cnblogs.com/Autumoon/category/112473.html/rss">(rss)</a></li>

<li><a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl04_Link" href="http://www.cnblogs.com/Autumoon/category/113499.html">LINQ 探索之旅(5)</a> <a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl04_RssLink" title="Subscribe to LINQ 探索之旅(5)" href="http://www.cnblogs.com/Autumoon/category/113499.html/rss">(rss)</a></li>

<li><a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl05_Link" href="http://www.cnblogs.com/Autumoon/category/158314.html">Office Live for Small Business(4)</a> <a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl05_RssLink" title="Subscribe to Office Live for Small Business(4)" href="http://www.cnblogs.com/Autumoon/category/158314.html/rss">(rss)</a></li>

<li><a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl06_Link" href="http://www.cnblogs.com/Autumoon/category/131874.html">白话C#系列(8)</a> <a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl06_RssLink" title="Subscribe to 白话C#系列(8)" href="http://www.cnblogs.com/Autumoon/category/131874.html/rss">(rss)</a></li>

<li><a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl07_Link" href="http://www.cnblogs.com/Autumoon/category/221050.html">读书笔记(1)</a> <a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl07_RssLink" title="Subscribe to 读书笔记(1)" href="http://www.cnblogs.com/Autumoon/category/221050.html/rss">(rss)</a></li>

<li><a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl08_Link" href="http://www.cnblogs.com/Autumoon/category/141025.html">多普达 Touch Diamond 创新前沿体验(4)</a> <a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl08_RssLink" title="Subscribe to 多普达 Touch Diamond 创新前沿体验(4)" href="http://www.cnblogs.com/Autumoon/category/141025.html/rss">(rss)</a></li>

<li><a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl09_Link" href="http://www.cnblogs.com/Autumoon/category/102692.html">公告(2)</a> <a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl09_RssLink" title="Subscribe to 公告(2)" href="http://www.cnblogs.com/Autumoon/category/102692.html/rss">(rss)</a></li>

<li><a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl10_Link" href="http://www.cnblogs.com/Autumoon/category/102688.html">技术杂文(3)</a> <a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl10_RssLink" title="Subscribe to 技术杂文(3)" href="http://www.cnblogs.com/Autumoon/category/102688.html/rss">(rss)</a></li>

<li><a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl11_Link" href="http://www.cnblogs.com/Autumoon/category/114802.html">简明设计模式——C#版(25)</a> <a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl11_RssLink" title="Subscribe to 简明设计模式——C#版(25)" href="http://www.cnblogs.com/Autumoon/category/114802.html/rss">(rss)</a></li>

<li><a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl12_Link" href="http://www.cnblogs.com/Autumoon/category/228064.html">时间管理(2)</a> <a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl12_RssLink" title="Subscribe to 时间管理(2)" href="http://www.cnblogs.com/Autumoon/category/228064.html/rss">(rss)</a></li>

</ul>

</div>

<div class="catList">
<h3 class="catListTitle">友情链接</h3>

<ul>

<li><a id="SingleColumn1_Categories_CatList_ctl01_LinkList_ctl01_Link" href="http://www.codeplex.com/site/users/view/Autumoon" target="_top">Autumoon @ CodePlex</a> </li>

<li><a id="SingleColumn1_Categories_CatList_ctl01_LinkList_ctl02_Link" href="http://zerocool.cnblogs.com/" target="_top">作者博客</a> <a id="SingleColumn1_Categories_CatList_ctl01_LinkList_ctl02_RssLink" title="Subscribe to 作者博客" href="http://www.cnblogs.com/ZeroCool/rss">(rss)</a></li>
<li style="margin-top: 2px;">/* ZeroCool的个人博客 */</li>
</ul>

</div>



<div class="catListComment">
<h3 class="catListTitle">最新评论<a id="SingleColumn1__3514896_RSSHyperlink1" title="RSS订阅最最新评论" href="http://www.cnblogs.com/Autumoon/CommentsRSS.aspx"><img title="RSS订阅最最新评论" src="xml.gif" style="border-width: 0px;"></a></h3>

	
			<div class="divRecentCommentAticle">
				<a id="SingleColumn1__3514896_CommentList_ctl00_Hyperlink2" class="listitem" href="http://www.cnblogs.com/Autumoon/archive/2008/08/18/1270558.html#1748817">1.&nbsp;Re:序</a>
			</div>
			<div class="divRecentComment">
				基础的东西很重要，往往出的Bug都是这些导致的，其实软件开发最重要的思想，单基础概念同样不可忽视。 (寒枫)
			</div>		
		
			<div class="divRecentCommentAticle">
				<a id="SingleColumn1__3514896_CommentList_ctl01_Hyperlink2" class="listitem" href="http://www.cnblogs.com/Autumoon/archive/2010/01/17/1649909.html#1748760">2.&nbsp;Re:把时间管理培养成习惯</a>
			</div>
			<div class="divRecentComment">
				nice article (王德水)
			</div>		
		
			<div class="divRecentCommentAticle">
				<a id="SingleColumn1__3514896_CommentList_ctl02_Hyperlink2" class="listitem" href="http://www.cnblogs.com/Autumoon/archive/2010/01/17/1649909.html#1748755">3.&nbsp;Re:把时间管理培养成习惯</a>
			</div>
			<div class="divRecentComment">
				地板，呵！道理浅显易懂，但很少人会这样进行时间管理，往往是做事前稍微考虑一下。养成好的习惯的确很重要。 (GoodGF)
			</div>		
		
			<div class="divRecentCommentAticle">
				<a id="SingleColumn1__3514896_CommentList_ctl03_Hyperlink2" class="listitem" href="http://www.cnblogs.com/Autumoon/archive/2010/01/17/1649909.html#1748728">4.&nbsp;Re:把时间管理培养成习惯</a>
			</div>
			<div class="divRecentComment">
				好文章 (长河落日)
			</div>		
		
			<div class="divRecentCommentAticle">
				<a id="SingleColumn1__3514896_CommentList_ctl04_Hyperlink2" class="listitem" href="http://www.cnblogs.com/Autumoon/archive/2010/01/09/1642846.html#1743368">5.&nbsp;Re:时间管理——被忽视的重要理念！</a>
			</div>
			<div class="divRecentComment">
				管理时间最有效的方法，就是建立良好的生活规律！

当我们手中握有大把的时间时，效率却不一定高；反之，在挤出的时间里，恰恰相反！
 (卡通一下)
			</div>		
		
</div>

<div class="catListView">
<h3 class="catListTitle">阅读排行榜</h3>
	
			<ul>
		
			<li>
				<a id="SingleColumn1_ctl02_TopList_ctl01_Hyperlink1" href="http://www.cnblogs.com/Autumoon/archive/2008/06/19/1225684.html">1.&nbsp;多线程(5901)</a>
			</li>
		
			<li>
				<a id="SingleColumn1_ctl02_TopList_ctl02_Hyperlink1" href="http://www.cnblogs.com/Autumoon/archive/2008/08/19/1271589.html">2.&nbsp;面向对象主要概念(3462)</a>
			</li>
		
			<li>
				<a id="SingleColumn1_ctl02_TopList_ctl03_Hyperlink1" href="http://www.cnblogs.com/Autumoon/archive/2008/06/23/1228335.html">3.&nbsp;反射(3172)</a>
			</li>
		
			<li>
				<a id="SingleColumn1_ctl02_TopList_ctl04_Hyperlink1" href="http://www.cnblogs.com/Autumoon/archive/2008/08/18/1270685.html">4.&nbsp;值类型和引用类型的区别(3056)</a>
			</li>
		
			<li>
				<a id="SingleColumn1_ctl02_TopList_ctl05_Hyperlink1" href="http://www.cnblogs.com/Autumoon/archive/2008/07/01/1233476.html">5.&nbsp;Touch Diamond Remote —— 世界就在指尖(2898)</a>
			</li>
		
			</ul>
		
</div>

<div class="catListFeedback">
<h3 class="catListTitle">评论排行榜</h3>
	
			<ul>
		
			<li>
				<a id="SingleColumn1_ctl03_TopList_ctl01_Hyperlink1" href="http://www.cnblogs.com/Autumoon/archive/2008/07/01/1233476.html">1.&nbsp;Touch Diamond Remote —— 世界就在指尖(38)</a>
			</li>
		
			<li>
				<a id="SingleColumn1_ctl03_TopList_ctl02_Hyperlink1" href="http://www.cnblogs.com/Autumoon/archive/2008/06/19/1225684.html">2.&nbsp;多线程(35)</a>
			</li>
		
			<li>
				<a id="SingleColumn1_ctl03_TopList_ctl03_Hyperlink1" href="http://www.cnblogs.com/Autumoon/archive/2008/08/19/1271589.html">3.&nbsp;面向对象主要概念(26)</a>
			</li>
		
			<li>
				<a id="SingleColumn1_ctl03_TopList_ctl04_Hyperlink1" href="http://www.cnblogs.com/Autumoon/archive/2008/08/26/1276746.html">4.&nbsp;寻找失落的SubString(23)</a>
			</li>
		
			<li>
				<a id="SingleColumn1_ctl03_TopList_ctl05_Hyperlink1" href="http://www.cnblogs.com/Autumoon/archive/2008/08/18/1270685.html">5.&nbsp;值类型和引用类型的区别(20)</a>
			</li>
		
			</ul>
		
</div>

				
<div id="blog_ad_google">
<h3>Google广告</h3>
<ul>
<li>

<ins style="border: medium none ; margin: 0pt; padding: 0pt; display: inline-table; height: 250px; position: relative; visibility: visible; width: 300px;"><ins style="border: medium none ; margin: 0pt; padding: 0pt; display: block; height: 250px; position: relative; visibility: visible; width: 300px;"><iframe allowtransparency="true" hspace="0" id="google_ads_frame3" marginheight="0" marginwidth="0" name="google_ads_frame" src="index_3.html" style="left: 0pt; position: absolute; top: 0pt;" vspace="0" scrolling="no" frameborder="0" height="250" width="300"></iframe></ins></ins>
</li>
</ul>
</div>
			</div>
			
		</div><!--end: sideBarMain -->
	</div><!--end: sideBar 侧边栏容器 -->
	<div class="clear"></div>
	</div><!--end: main -->
	<div class="clear"></div>
	<div id="footer">
		
<!--done-->
Copyright ©2010 Autumoon
	</div><!--end: footer -->
</div><!--end: home 自定义的最大容器 -->
    </form>
	
	
      
    
    
    
</body>
</html>
